#include <bits/stdc++.h>
using namespace std;
int T,n,aa[200005],a1,a0,ecf[21]={0},ans,ans1;
short bb[200005];
long long ans,ans1;
int dg(int x1,int x0,int sd){
    if(x0==s)
    if(bb[sd]>1&&x1==-1)x1=bb[sd];
}
void sds(){
    set<int> s;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&aa[i]);
        if(s.count(aa[i]))bb[i]=1;
        else s.insert(aa[i]),bb[i]=0;
    }
    s.clear();
    for(int i=n;i>0;i--){
        if(s.count(aa[i]))bb[i]+=2;
        else s.insert(aa[i]);
    }
    a1=-1;
    a0=-1;
    for(int i=1;i<=ect[n];i++){
        s=n;
        for(int j=1;j<=n;j++){
            if(i%ecf[j]==0){
                if(a0==-1)a0=aa[j];
                else{
                    if(a0==aa[j])ans1+=aa[j];
                    else a0=aa[j];
                }
            }
            else{
                if(a1==-1)a1=aa[j];
                else{
                    if(a1==aa[j])ans1+=aa[j];
                    else a1=aa[j];
                }

            }
        }
        if(ans1>ans)ans=ans1;
    }
    printf("%lld",ans);
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    for(int i=1;i<=20;i++)ecf[i]=ecf[i-1]*2;
    scanf("%d",&T);
    while(T--)sds();
    return 0;
}
